<template>
  <el-card class="box-card">
    <el-tabs v-model="activeName">
      <!-- 角色管理页面 -->
      <el-tab-pane label="角色管理" name="first" class="rolePage">
        <el-button type="primary" size="mini" class="addrole">+ 新增角色</el-button>
        <!-- 表格 -->
        <el-table :data="roleList" style="width: 100%" border>
          <el-table-column label="序号" type="index" width="180"></el-table-column>
          <el-table-column prop="name" label="角色名" width="180"></el-table-column>
          <el-table-column prop="description" label="描述" width="180"></el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="handleDelivery(scope.$index, scope.row)"
              >分配权限</el-button>
              <el-button size="mini" type="text" @click="handleEdit(scope.$index, scope.row)">修改</el-button>
              <el-button size="mini" type="text" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页 -->
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="pageSizes"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        ></el-pagination>
      </el-tab-pane>
      <!-- 公司信息页面 -->
      <el-tab-pane label="公司信息" name="second">
        <!-- <div style="margin: 20px;"></div> -->
        <el-form label-width="180px" class="companyInfo">
          <el-form-item label="企业名称">
            <el-input disabled :value="companyInfo.name"></el-input>
          </el-form-item>
          <el-form-item label="公司地址">
            <el-input disabled :value="companyInfo.companyAddress"></el-input>
          </el-form-item>
          <el-form-item label="公司电话">
            <el-input disabled :value="companyInfo.companyPhone"></el-input>
          </el-form-item>
          <el-form-item label="邮箱">
            <el-input disabled :value="companyInfo.mailbox"></el-input>
          </el-form-item>
          <el-form-item label="备注">
            <el-input disabled :value="companyInfo.remarks"></el-input>
          </el-form-item>
        </el-form>
      </el-tab-pane>
    </el-tabs>
  </el-card>
</template>

<script>
import { getCompanyApi, getRoleListApi } from "@/api/setting";
export default {
  data() {
    return {
      activeName: "first",
      roleList: [
        {
          name: "王小虎",
          description: "上海市普陀区金沙江路 1516 弄"
        }
      ],
      currentPage: 1, //当前页码
      pageSizes: [2, 3, 4, 5], //可选页容量，即  XX条/页
      pageSize: 2, //当前页容量
      total: 10, //总共多少条
      companyInfo: {}
    };
  },
  methods: {
    async getCompany() {
      // 得到公司id
      const companyId = this.$store.getters.userInfo.companyId;
      const res = await getCompanyApi(companyId);
      this.companyInfo = res.data;
    },
    async getRoleList() {
      const pages = {
        page: this.currentPage,
        pagesize: this.pageSize
      };
      const res = await getRoleListApi(pages);
      console.log(res);
      this.total = res.data.total;
      this.roleList = res.data.rows;
    },
    handleEdit(index, row) {
      console.log(index, row);
    },
    handleDelete(index, row) {
      console.log(index, row);
    },
    handleDelivery(index, row) {
      console.log(index, row);
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.pageSize = val;
      this.getRoleList();
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.currentPage = val;
      this.getRoleList();
    }
  },
  created() {
    this.getCompany();
    this.getRoleList();
  }
};
</script>

<style lang="scss">
.box-card {
  margin: 20px;
}
.companyInfo {
  width: 800px;
}
.rolePage {
  margin: 0 30px;
  .addrole {
    margin: 30px 0;
  }
}
</style>
